<template>
    <div>
        <!-- 添加收货地址顶部导航区域 -->
        <nav-comp :back="true" title="添加收货地址"></nav-comp>
        <!-- 地址表单区域 -->
        <van-address-edit
            :area-list="areaList"
            show-postal
            show-delete
            :area-columns-placeholder="['请选择', '请选择', '请选择']"
            @save="onSave"
            @delete="onDelete"
        />
    </div>
</template>

<script>
import { areaList } from '@vant/area-data';
export default {
    data() {
        return {
            areaList,//省市区联动数据
            userUid:"",//用户的uid
        };
    },
    mounted() {
        //1.检测是否登录
        let userUid = this.$api.isLogin()
        if(userUid !=false){
            this.userUid = userUid
        }
    },
    methods: {
        //1.提交地址数据
        onSave(info){
            //1.1获取提交数据 组装数据
            let insertData = {
                uid:this.userUid,
                username:info.name,
                userphone:info.tel,
                location:info.province+info.city+info.county,
                useraddress:info.addressDetail,
                status:info.isDefault ? 1 : 0  
            }
            //1.2验证数据格式

            //1.3执行提交请求
            this.$api.reqAddressAdd(insertData)
            .then(res=>{
                this.$router.push('/orderconfirm')
            })
            .catch(err=>console.log(err))
        },

        //2.删除表单中的地址数据
        onDelete(){},
    },
};
</script>

<style scoped>
</style>
